package com.foo.Businesstest;

import static org.junit.Assert.assertEquals;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;
import facade.FacadeInterfaceServiceStub;
import facade.GetEventsByKeywordFaultException;
import facade.GetFacadeGlobalDataFaultException;
import facade.GetMovieInfoByGenreFaultException;
import facade.GetMovieInfoByNameFaultException;
import facade.GetNewsByCategoryFaultException;
import facade.GetRestaurantInfoByCusineFaultException;
import facade.GetRestaurantInfoByNameFaultException;
import org.example.www.globalsearch.GetAllData;
import org.example.www.globalsearch.GetAllDataResponse;
import org.globalSearchexample.ws.GetAllDataFaultException;
import org.globalSearchexample.ws.GlobalSearchStub;
//import org.example.www.newwsdlfile.GetAllGlobalData;
//import org.example.www.newwsdlfile.GetAllGlobalFacadeDataResponse;
import org.junit.Test;
import org.sjsufacade.www.facadeinterfaceservice.GetEventsByKeyword;
import org.sjsufacade.www.facadeinterfaceservice.GetEventsByKeywordResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetFacadeGlobalData;
import org.sjsufacade.www.facadeinterfaceservice.GetFacadeGlobalDataResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByGenre;
import org.sjsufacade.www.facadeinterfaceservice.GetMovieInfoByGenreResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetNewsByCategory;
import org.sjsufacade.www.facadeinterfaceservice.GetNewsByCategoryResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfoByCusine;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfoByCusineResponse;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfoByName;
import org.sjsufacade.www.facadeinterfaceservice.GetRestaurantInfoByNameResponse;

import facade.FacadeBusiness;

//import facade.FacadeBusiness;
//import facade.GetAllGlobalDataFaultException;


public class FacadeBussinessTest 
{
	
	@Test
	public void getGlobalData() throws AxisFault
	{
		FacadeBusiness buss = new FacadeBusiness();
		GetFacadeGlobalData getAllGData = new GetFacadeGlobalData();
		getAllGData.setIn("");
		try {
			GetFacadeGlobalDataResponse response = new GetFacadeGlobalDataResponse();
			response = buss.getFacadeGlobalData(getAllGData);
			assertEquals(50,response.getOut().getRestaurantData().getRestaurantList().length);
			assertEquals(70,response.getOut().getMovieData().getMovieList().length);
		} catch (GetFacadeGlobalDataFaultException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void getRestaurantData() throws AxisFault
	{
		FacadeBusiness buss = new FacadeBusiness();
		GetRestaurantInfoByCusine getRestaurantInfoByCusine = new GetRestaurantInfoByCusine();
		getRestaurantInfoByCusine.setIn("Indian");
		try {
			GetRestaurantInfoByCusineResponse response = new GetRestaurantInfoByCusineResponse();
			response = buss.getRestaurantInfoByCusine(getRestaurantInfoByCusine);
			assertEquals(11,response.getOut().getRestaurantList().length);
		} catch (GetRestaurantInfoByCusineFaultException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Test
	public void getMovieData() throws AxisFault
	{
		FacadeBusiness buss = new FacadeBusiness();
		GetMovieInfoByGenre getMInfoByName = new GetMovieInfoByGenre();
		getMInfoByName.setIn("Comedy");
		try {
			GetMovieInfoByGenreResponse response = new GetMovieInfoByGenreResponse();
			response = buss.getMovieInfoByGenre(getMInfoByName);
			System.out.println("Actual Length" + response.getOut().getMovieList().length);
			assertEquals(15,response.getOut().getMovieList().length);
		} catch (GetMovieInfoByGenreFaultException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void getNewsData() throws AxisFault
	{
		FacadeBusiness buss = new FacadeBusiness();
		GetNewsByCategory getNInfoByName = new GetNewsByCategory();
		getNInfoByName.setIn("Comedy");
		try {
			GetNewsByCategoryResponse response = new GetNewsByCategoryResponse();
			response = buss.getNewsByCategory(getNInfoByName);
			System.out.println("Actual Length" + response.getOut().getNews_list().length);
			assertEquals(7,response.getOut().getNews_list().length);
		} catch (GetNewsByCategoryFaultException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void getEventsData() throws AxisFault
	{
		FacadeBusiness buss = new FacadeBusiness();
		GetEventsByKeyword getEventsByKeyword = new GetEventsByKeyword();
		getEventsByKeyword.setIn("");
		try {
			GetEventsByKeywordResponse response = new GetEventsByKeywordResponse();
			response = buss.getEventsByKeyword(getEventsByKeyword);
			System.out.println("Actual Length" + response.getOut().getEventList().length);
			assertEquals(1,response.getOut().getEventList().length);
		} catch (GetEventsByKeywordFaultException e) {
			System.out.println(e.getMessage());
		}
	}
	
	private static final String FACADE_SERVICE_END_POINT ="http://localhost:8080/axis2/services/FacadeInterfaceService";
	public FacadeInterfaceServiceStub fStub;
	//Network Call
	@Test
	public void getAllDataByNetwork() throws GetAllDataFaultException
	{
		try {
			fStub = new FacadeInterfaceServiceStub(FACADE_SERVICE_END_POINT);
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		GetRestaurantInfoByCusine param = new GetRestaurantInfoByCusine();
		param.setIn("Indian");
		GetRestaurantInfoByCusineResponse rRes = new GetRestaurantInfoByCusineResponse();
		try {
			rRes = fStub.getRestaurantInfoByCusine(param);
		} catch (RemoteException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (GetRestaurantInfoByCusineFaultException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		GetFacadeGlobalData getDataParam = new GetFacadeGlobalData();
		getDataParam.setIn("");
		GetFacadeGlobalDataResponse res= new GetFacadeGlobalDataResponse();
		try {
			res = fStub.getFacadeGlobalData(getDataParam);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (GetFacadeGlobalDataFaultException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		assertEquals(50,res.getOut().getRestaurantData().getRestaurantList().length);
		//assertEquals(70,res.getOut().getMovieData().getMovie().length);
	}

}
